<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Request\CntctDedupRequest;
use App\CustHub\Service\ChContactDedupService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

/**
 * 联系人去重
 */
#[Controller('ch/cntctDedup')]
class ContactDedupController extends BaseController
{
    #[Inject]
    protected ChContactDedupService $service;

    /**
     * 开始检测
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('startDetection')]
    public function startDetection(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success(['id'=>$this->service->startDetection($request->all())]);
    }

    /**
     * 详情
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getTaskInfo')]
    public function getTaskInfo(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getTaskInfo($request->all()));
    }

    /**
     * 重复客户列表
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('repeatContactList')]
    public function repeatContactList(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->repeatContactList($request->all()));
    }

    /**
     * 重新检测
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('restartDetection')]
    public function restartDetection(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success(['id'=>$this->service->restartDetection($request->all())]);
    }

    /**
     * 取消检测
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('cancelDetection')]
    public function cancelDetection(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->cancelDetection($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 取消检测
     * @param CntctDedupRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('sort')]
    public function sort(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->sort($request->all()) ? $this->success() : $this->error();
    }

    #[PostMapping('deduplication')]
    public function deduplication(CntctDedupRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deduplication($request->all()) ? $this->success() : $this->error();
    }
}